package com.woniuxy.controller;

import com.woniuxy.entity.WebSocketMessage;
import com.woniuxy.mapper.WebSocketMessageMapper;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/chat")
public class ChatController {
    @Resource
    private WebSocketMessageMapper webSocketMessageMapper;
    @GetMapping("/history")
    public List<WebSocketMessage> getChatHistory(@RequestParam String senderPhone,@RequestParam String receiverPhone){
        return  webSocketMessageMapper.queryByPhone(senderPhone,receiverPhone);
    }
    @PostMapping("/read/{senderPhone}/{receiverPhone}")
    public void markAsRead(@PathVariable("senderPhone") String senderPhone,@PathVariable("receiverPhone") String receiverPhone){
        webSocketMessageMapper.updateMessageRead(senderPhone,receiverPhone);
    }
}
